package com.kkb.shopcenter.controller;



import com.github.pagehelper.PageInfo;
import com.kkb.shopcenter.api.RoleInfoService;
import com.kkb.shopcenter.api.UserInfoService;
import com.kkb.shopcenter.common.common.HttpResult;
import com.kkb.shopcenter.common.pojo.RoleInfo;
import com.kkb.shopcenter.common.pojo.UserInfo;
import com.kkb.shopcenter.common.utils.SecurityUtils;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/api/roleController")
@Controller
public class RoleController {

    @Reference
    public RoleInfoService roleInfoService;

    @Reference
    private UserInfoService userInfoService;

    /**
     * 查询所有角色
     * @return
     */
    //@PreAuthorize("hasAnyRole('admin')")
    @GetMapping("/roleList")
    @ResponseBody
    public HttpResult getRoleList(@RequestParam(value="page",defaultValue="1")int pageNo, @RequestParam(value="pageSize",defaultValue="10")int pageSize){
        UserInfo userInfo = userInfoService.findByUsername(SecurityUtils.getUserName());
        PageInfo<RoleInfo> pageInfo=roleInfoService.getRoleList(userInfo.getType(),pageNo+1,pageSize);

        return HttpResult.success(pageInfo);
    }


}
